package com.bjsc.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;

/**
 * @author create by VIC.Huang
 * @date 2018/3/4
 */
@Mapper
public interface IndexMapper {
    /**
     * 查询注册用户数
     * @param type  0:所有  1:当月  2：当日
     * @return
     */
    @Select("<script>" +
            "select count(1) from t_user where system = 'NO'" +
            "<if test=\"type == 1\"> and MONTH(create_time) = MONTH(NOW())</if>" +
            "<if test=\"type == 2\"> and TO_DAYS(create_time)=TO_DAYS(NOW())</if>" +
            "</script>")
    int countRegisterUsers(@Param("type") int type);

    /**
     * 查询总充值
     * @param type  0:所有  1:当月  2：当日
     * @return
     */
    @Select("<script>" +
            "select sum(tsr.money) from t_spend_record tsr " +
            "join t_user tu on tsr.user_id = tu.id and tu.system = 'NO' " +
            "where tsr.type = 'RECHARGE'" +
            "<if test=\"type == 1\"> and MONTH(tsr.create_time) = MONTH(NOW())</if>" +
            "<if test=\"type == 2\"> and TO_DAYS(tsr.create_time)=TO_DAYS(NOW())</if>" +
            "</script>")
    BigDecimal sumRechargeMoney(@Param("type")int type);

    /**
     * 查询总提现（已处理）
     * @param type  0:所有  1:当月  2：当日
     * @return
     */
    @Select("<script>" +
            "select sum(money) from t_withdraw_record twr " +
            "join t_user tu on twr.user_id = tu.id and tu.system = 'NO' " +
            "where twr.handle_status = 'YES' " +
            "<if test=\"type == 1\"> and MONTH(twr.create_time) = MONTH(NOW())</if>" +
            "<if test=\"type == 2\"> and TO_DAYS(twr.create_time)=TO_DAYS(NOW())</if>" +
            "</script>")
    BigDecimal sumWithdrawMoney(@Param("type")int type);

    /**
     * 用户总余额
     * @return
     */
    @Select("select sum(asset) from t_user_asset tua " +
            "join t_user tu on tua.user_id = tu.id and tu.system = 'NO' and tu.`disable` = 0")
    BigDecimal sumUserAsset();
}
